package com.tengju.support.domain.model.rule;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import org.springframework.util.StringUtils;

@AllArgsConstructor
public enum Operation {
    /**
     * MATH
     */
    GT(">","大于"),
    LT("<","小于"),
    EQ("=","等于"),
    NEQ("!=","不等于"),
    GE(">=","大于等于"),
    LE("<=","小于等于"),
    IN("IN","包含"),
    NOT_IN("NOTIN","不包含"),
    RIGHT_LIKE("RLIKE","右匹配"),
    LEFT_LIKE("LLIKE","左匹配"),
    IS_EMPTY("ISEMPTY","为null"),
    IS_NOT_EMPTY("ISNOTEMPTY","非null"),


    /**
     * TIME
     */
    IS_TODAY("isToday","是当天"),
    IS_NOT_TODAY("isNotToday","不是当天"),
    ;

    private final String val;
    private final String desc;

    @JsonValue
    public String getVal() {
        return val;
    }

    @JsonCreator
    public static Operation parseByVal(String val) {

        if (StringUtils.isEmpty(val)) {
            return null;
        }

        for (Operation operation : values()) {
            if (operation.val.equals(val)) {
                return operation;
            }
        }
        return null;
    }

}
